<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="lib/layui/css/layui.css" media="all" />

</head>
<body>
	<input type="hidden" name="fucker" id="edit">
	<div class="layui-container" style="margin-top: 20px">
		<form class="layui-form" lay-filter="expressForm" id="empData">
			
			<div class="layui-form-item"
				style="padding-top: 15px; margin-right: 45px;">
				<label class="layui-form-label">编号：</label>
				<div class="layui-input-block">
					<input type="text" name="express_company_id"
						lay-verify="required" autocomplete="off" class="layui-input">
				</div>
			</div>
		
			<div class="layui-form-item"
				style="padding-top: 15px; margin-right: 45px;">
				<label class="layui-form-label">名称：</label>
				<div class="layui-input-block">
					<input type="text" name="express_company_name"
						lay-verify="required" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item" style="margin-right: 45px;">
				<label class="layui-form-label">电话：</label>
				<div class="layui-input-block">
					<input type="text" name="phonenumber" lay-verify="required"
						autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item" style="margin-right: 45px;">
				<label class="layui-form-label">快递公司编码：</label>
				<div class="layui-input-block">
					<input type="text" name="express_company_code"
						lay-verify="required" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item"
				style="padding-top: 15px; margin-right: 45px;">
				<label class="layui-form-label">备注：</label>
				<div class="layui-input-block">
					<input type="text" name="remarks" autocomplete="off"
						class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" id="submit" lay-submit
						lay-filter="expressForm">
						<i class="layui-icon">提交</i>
					</button>
					<button type="reset" class="layui-btn layui-btn-primary">
						<i class="layui-icon">重置</i>
					</button>
				</div>
			</div>
		</form>
	</div>
</body>
<script type="text/javascript" src="lib/layui/layui.js"></script>
<script>
	//Demo
	layui.use([ 'form', 'layer', 'jquery' ], function() {
		form = layui.form;
		var upload = layui.upload;
		form.render('select', 'test1');
		$ = layui.jquery;
			 /* var edit = JSON.parse($("#edit").val());
			$("[name=express_company_name]").val(edit.express_company_name);
			$("[name=express_company_id]").val(edit.express_company_id);
			$("[name=phonenumber]").val(edit.phonenumber);
			$("[name=express_company_code]").val(edit.express_company_code);
			$("[name=remarks]").val(edit.remarks);  */
			
			var value = $("#edit").val();
			var edit = null;
			if (value.length != 0) {
			 edit = JSON.parse($("#edit").val());
			form.val("expressForm",edit);
			}
			
				
			

		//监听提交
		form.on('submit(expressForm)', function(data) {
			var params = data.field;
			var index = top.layer.msg('数据提交中，请稍候', {
				icon : 16,
				time : false,
				shade : 0.8
			});
			var method = "";
			if (edit == null || edit == undefined) {
				method = "add";
			} else {
				method = "update";
			}
			
			$.post("api/carrier?op="+method,params,function(d){
				if (d.code == 200) {
					top.layer.close(index);
		            top.layer.msg("员工添加成功！");
		            layer.closeAll("iframe");
		            //刷新父页面
		            parent.location.reload();
				} else {
					layer.msg(d.msg,{"icon":2});
				}
			});
			
			/* $.ajax({
				url : "api/carrier?op=" + method,
				type : "post",
				data : params,
				success : function(r) {
					layer.close(index);
					layer.msg("快递公司添加成功！");
					layer.closeAll("iframe");
					parent.location.reload();
				},
				error : function(r) {
					layer.msg(r.msg, {
						"icon" : 2
					});
				}为啥一直转圈圈？
			}) */

			return false;
		});

	});
</script>


</html>